package sketch.shape.geom.prim;

import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;


public class Point {

	private Point2D.Double point;

	public Point(double x, double y) {
		point = new Point2D.Double(x, y);
	}

	public Point(Point2D p2d) {
		point = new Point2D.Double(p2d.getX(), p2d.getY());
	}

	public Point(Point p) {
		this(p.getX(), p.getY());
	}

	public Point() {
		this(0, 0);
	}

	public Point clone() {
		Point2D p = (Point2D) point.clone();
		return new Point(p.getX(), p.getY());
	}

	public double distance(double arg0, double arg1) {
		return point.distance(arg0, arg1);
	}

	public double distance(Point arg0) {
		return point.distance(arg0.toPoint2D());
	}

	public double distanceSq(double arg0, double arg1) {
		return point.distanceSq(arg0, arg1);
	}

	public double distanceSq(Point arg0) {
		return point.distanceSq(arg0.toPoint2D());
	}

	public double getX() {
		return point.getX();
	}

	public double getY() {
		return point.getY();
	}

	public int intX() {
		return (int) getX();
	}

	public int intY() {
		return (int) getY();
	}

	public Point2D toPoint2D() {
		return new Point2D.Double(getX(), getY());
	}

	public Point subtract(Point mate) {
		return new Point(getX() - mate.getX(), getY() - mate.getY());
	}

	public Point add(Point mate) {
		return new Point(getX() + mate.getX(), getY() + mate.getY());
	}

	public Point add(double x, double y) {
		return new Point(getX() + x, getY() + y);
	}

	public Point add(gVector vec, double scale) {
		gVector add = vec.unitized().multiply(scale);
		return new Point(getX() + add.x(), getY() + add.y());
	}

	public gVector dir() {
		return new gVector(getX(), getY());
	}

	public String toString() {
		return "(" + getX() + "," + getY() + ")";
	}

	public boolean identical(Point arg0) {
		return (intX() == arg0.intX()) && (intY() == arg0.intY());
	}

	public java.awt.Shape getBound() {
		return new Ellipse2D.Double(getX()-2, getY()-2, 4, 4);
	}

	public Point add(gVector vec) {
		return new Point(getX() + vec.x(), getY() + vec.y());
	}

	public Point linearInterpolate(Point mate, double weightForThis) {
		double weightForThat = 1.0 - weightForThis;
		return new Point(this.getX() * weightForThat + mate.getX()
				* weightForThis, this.getY() * weightForThat + mate.getY()
				* weightForThis);
	}

	public static Point parsePoint(String string) {
		string = string.replace("(", "");
		string = string.replace(")", "");
		String[] parts = string.split(",");
		if (parts.length < 2) {
			return null;
		}

		return new Point(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]));
	}
}
